

#include "dtstruct.h"

void InitQueue (CQUEUE *q , TASK * task ) { 
	q->front = 0 ;
	q->rear = 0 ;
	q->length = 0 ; 
	q->task = task ;
}
int EnQueue (CQUEUE *q, INTDATA data ) {
	if (FullQueue (q)){
		return false ; 
	}
	q->data[q->rear] = data ;
	q->rear = (q->rear+1)% QUE_SIZE;
	q->length = q->length +1;

	if (q->task !=0){ 
		if (q->task->flags !=TASK_STATUS_ACTIVE) { 
			task_run (q->task ,-1 ,0 ) ;
		}
	}
	return true; 
}

int DeQueue (CQUEUE *q ,INTDATA *data ) {
	if (EmptyQueue (q)){
		return false ; 
	}
	
	*data = q->data[q->front] ;
	q->front = (q->front +1)% QUE_SIZE ;
	q->length -=1 ;  
	return true ;
}

int FullQueue (CQUEUE *q) {
	if (q->front ==q->rear && q->length > 0){ 
		return true ;
	}
	return false ;
}

int EmptyQueue (CQUEUE *q ){ 
	if (q->front ==q->rear && q->length <= 0){ 
		return true ;
	}
	return false ;	
}  
  